<%@ page language="java" import="java.util.*,com.tjsinfo.tjsoa.common.DealString,com.tjsinfo.tjsoa.system.vo.TSystemDepartment" pageEncoding="UTF-8"%>
<%@page import="com.tjsinfo.tjsoa.common.PaginationSupport;"%>
<%
response.setHeader("Expires", "Sat, 6 May 1995 12:00:00 GMT");

// 设置 HTTP/1.1 no-cache 头
response.setHeader("Cache-Control", "no-store,no-cache,must-revalidate");

// 设置 IE 扩展 HTTP/1.1 no-cache headers， 用户自己添加
response.addHeader("Cache-Control", "post-check=0, pre-check=0");

// 设置标准 HTTP/1.0 no-cache header.
response.setHeader("Pragma", "no-cache");

String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
DealString ds=new DealString();
PaginationSupport paginationSupport=(PaginationSupport)request.getAttribute("paginationSupport");

List<TSystemDepartment> list=(List)request.getAttribute("departmentlist");
String pageNoStr = request.getParameter("pageNo");
if (pageNoStr == null)pageNoStr = "0";
Integer pageNo = Integer.valueOf(pageNoStr);
String level=request.getParameter("level");
String id=request.getParameter("id");
Random random=new Random();
int tar=random.nextInt();
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Cache-Control" content="no-cache"/>
<title>粮油集团办公自动化协作平台</title>
<link href="<%=basePath %>style/txlk7.css" rel="stylesheet" type="text/css" />
<script src="<%=basePath%>js/common/move/move.js" type=text/javascript></script>
<script type="text/javascript">
function submitpages(value){
	if(value==-1){
		alert("请重新选择页码!");
		return ;
	}
	window.location.href='<%=basePath%>tjsinfo/tjsoa/system/departmentManage.do?method=departmentList&pageNo='+value+'&level=<%=level %>&id=<%=id %>';
}
function isEmpty(str){
	if(str==null || str.length==0) return true;
	else 
	return false;
}
function isChinese(str){
	var badChar = "0123456789";
	badChar += " "+"　";//半角与全角空格
	badChar += ".*`~!@#$%^&()-_=+]\\|:;\"\\'<,>?/";//不包含*或.的英文符号
	if(""==str){     
	return false;     
	}
	for(var i=0;i<str.length;i++){
		var c = str.charAt(i);
		if(badChar.indexOf(c) > -1){     
			return false;    
		}     
	}     
	return true;     
}
function changepage(){
	//window.location.href='<%=basePath%>tjsinfo/tjsoa/system/departmentList.do?level='+len+'&id='+ids;
	//window.location.href="a.html";
	//$("#tete").click();
	var len=document.getElementById("len").value;
	var ids=document.getElementById("ids").value;
	window.open('<%=basePath%>tjsinfo/tjsoa/system/departmentManage.do?method=departmentList&level='+len+'&id='+ids,"mainFrame");
}
function departDel(level,id,did,tar){
	if(confirm('你确认要删除吗?\r删除后不能恢复.\r请慎重操作.')){
		window.location.href='<%=basePath%>tjsinfo/tjsoa/system/departmentManage.do?method=departmentDel&level='+level+'&id='+id+'&did='+did+'&tar='+tar;
	}
}
function test(){
	$("#windowOpen").click();
}
function updateOrderc(myid){
	
	document.getElementById("myid").value=myid;
	$("#updateOrderNoWindow").click();
}
</script>
<script type="text/javascript" src="<%=basePath %>js/xyTree/TreeNormal.js"></script>
<script type="text/javascript" src="<%=basePath %>js/xyTree/NodeNormalChangePage.js"></script>
<script type="text/javascript" src="<%=basePath %>js/xyTree/DivTreeNormal.js"></script>
<script type="text/javascript" src="<%=basePath %>js/xyTree/js/allOrganizeClick.js?<%=tar %>"></script>
<script type="text/javascript">
	//初始化方法
	function init(){
	  document.getElementById('tree').appendChild(treeFenju3.div);
	  treeFenju3.init(huidiao_Example3_Node);//初始化方法不同
	}
	function expand2(){
	  alert();
	}
	
	function huidiao_Example3_Node(node){
	  //打印3个属性，节点的属性只有name是必须的，别的是在js文件自行添加
	  var ids=node.id;
	  var names=node.name;
	  var len=ids.toString().length/2;
	  document.getElementById("ids").value=ids;
	  document.getElementById("len").value=len;
	  changepage();
	}
	//定义初始化程序
	window.onload = init;
</script>
<script src="<%=basePath%>js/common/move/idrag.js" type=text/javascript></script>
<script src="<%=basePath%>js/common/move/idrop.js" type=text/javascript></script>
<script src="<%=basePath%>js/common/move/iutil.js" type=text/javascript></script>
<script src="<%=basePath%>js/common/move/iresizable.js" type=text/javascript></script>
<script src="<%=basePath%>js/common/move/ifxtransfer.js" type=text/javascript></script>
<style type=text/css media=all>
#container {
    width:600px;
    height:300px;
    border:3px solid #c3daf9;
}
#window {
	DISPLAY: none;
	LEFT: 200px;
	OVERFLOW: hidden;
	WIDTH: 600px;
	POSITION: absolute;
	TOP: 100px;
	HEIGHT: 200px
}

#windowTop {
	BACKGROUND-POSITION: right top;
	BACKGROUND-IMAGE: url(<%=basePath%>js/common/move/images/window_top_end.png);
	OVERFLOW: hidden;
	CURSOR: move;
	BACKGROUND-REPEAT: no-repeat;
	POSITION: relative;
	HEIGHT: 30px
}

#windowTopContent {
	BACKGROUND-POSITION: left top;
	FONT-WEIGHT: bold;
	FONT-SIZE: 14px;
	BACKGROUND-IMAGE: url(<%=basePath%>js/common/move/images/window_top_start.png)
		;
	OVERFLOW: hidden;
	COLOR: #206D85;
	TEXT-INDENT: 10px;
	LINE-HEIGHT: 30px;
	MARGIN-RIGHT: 13px;
	BACKGROUND-REPEAT: no-repeat;
	FONT-FAMILY: Arial, Helvetica, sans-serif;
	HEIGHT: 30px
}

#windowMin {
	RIGHT: 25px;
	CURSOR: pointer;
	POSITION: absolute;
	TOP: 10px
}

#windowMax {
	DISPLAY: none;
	RIGHT: 25px;
	CURSOR: pointer;
	POSITION: absolute;
	TOP: 10px
}

#windowClose {
	RIGHT: 10px;
	CURSOR: pointer;
	POSITION: absolute;
	TOP: 10px
}

#windowBottom {
	BACKGROUND-POSITION: right bottom;
	BACKGROUND-IMAGE:
		url(<%=basePath%>js/common/move/images/window_bottom_end.png);
	BACKGROUND-REPEAT: no-repeat;
	POSITION: relative;
	HEIGHT: 170px
}

#windowBottomContent {
	BACKGROUND-POSITION: left bottom;
	BACKGROUND-IMAGE:
		url(<%=basePath%>js/common/move/images/window_bottom_start.png);
	MARGIN-RIGHT: 13px;
	BACKGROUND-REPEAT: no-repeat;
	POSITION: relative;
	HEIGHT: 170px
}

#windowResize {
	RIGHT: 3px;
	CURSOR: se-resize;
	BOTTOM: 5px;
	POSITION: absolute
}

#windowContent {
	BORDER-RIGHT: #6caf00 1px solid;
	BORDER-TOP: #6caf00 1px solid;
	FONT-SIZE: 11px;
	LEFT: 10px;
	OVERFLOW: auto;
	BORDER-LEFT: #6caf00 1px solid;
	WIDTH: 575px;
	MARGIN-RIGHT: 10px;
	BORDER-BOTTOM: #6caf00 1px solid;
	FONT-FAMILY: Arial, Helvetica, sans-serif;
	POSITION: absolute;
	TOP: 30px;
	HEIGHT: 155px;
	BACKGROUND-COLOR: #fff
}
#zx {
	HEIGHT: 145px;
	OVERFLOW: auto;
	height: 95%;
}

.transferer2 {
	BORDER-RIGHT: #6baf04 1px solid;
	BORDER-TOP: #6baf04 1px solid;
	FILTER: alpha(opacity =       30);
	BORDER-LEFT: #6baf04 1px solid;
	BORDER-BOTTOM: #6baf04 1px solid;
	BACKGROUND-COLOR: #b4f155;
	-moz-opacity: 0.3;
	opacity: 0.3
}
</style>
</head>

<body>
<div id="right">
<div style="height:92%">
      <div class="p_011">
		    <ul>
                <li class="s02"><a style="cursor: hand" id="windowOpen"><%if(!level.equals("8")){ %>新建部门<%} %></a></li>
            </ul>
	  </div>
      <table width="100%" border="0" cellspacing="0" cellpadding="0" height="100%">
          <tr>
            <td width="35%" valign="top" align="left" height="100%">
              <div class="conren">
				<div class="h">
					<table width="100%" border="0" cellspacing="0" cellpadding="0">
                      <tr>
                        <td width="10%" align="center"><img src="<%=basePath %>images/949_033.gif" /></td>
                        <td align="left">部门管理<input id="len" name="len" type="hidden"/>
                        <input id="ids" name="ids" type="hidden"/>
                        </td>
                      </tr>
                    </table>
                </div>
                <div id="tree" style="overflow: auto;height:95%;width:100%;">
		        </div>
              </div>
            </td>
            <td width="65%" valign="top" height="100%">
               <div class="contab">
                  <table class="p_06" width="100%" border="0" cellspacing="0">
                      <tr>
                        <th width="60%">部门名称</th>
                        <th width="8%">序号</th>
                        <th width="32%"><a style="cursor: hand" id="updateOrderNoWindow">操作</a></th>
                    </tr>
                    <%
                    String name="";
                    int i=1;
                    for(TSystemDepartment departs:list){
						name=departs.getDeptName();
						if(name.length()>20)name=ds.substring(name,20);
						i++;
					%>
                      <tr <%if(i%2==0)out.print("bgcolor='#F4F4F4'"); %>>
                        <td><%if(departs.getIsDel()==0){%><font color="red"><%=name %></font> <%}else{ %><%=name %> <%} %></td>
                        <td><%=departs.getOrderNo() %></td>
                        <td>
                        	<%if(!level.equals("8")){ %><a href="javascript:test();" >添加部门</a>|<%} %>
                        	<%if(!"0".equals(departs.getRemarks())) {if(departs.getIsDel()==1){%>
	                        	<a href="<%=basePath%>tjsinfo/tjsoa/system/departmentManage.do?method=departmentDel&level=<%=level %>&id=<%=id %>&did=<%=departs.getId().trim() %>&tar=<%=tar %>">禁用</a>
	                        	<%}else{ %>
	                        	<a href="<%=basePath%>tjsinfo/tjsoa/system/departmentManage.do?method=departmentDel&level=<%=level %>&id=<%=id %>&did=<%=departs.getId().trim() %>&tar=<%=tar %>">激活</a>
	                        	<%}}else{ %>
	                        	<a onclick="departDel('<%=level %>','<%=id %>','<%=departs.getId().trim() %>','<%=tar %>');" style="cursor:hand">删除</a>
                        	<%} %>|<a style="cursor: hand" onclick="updateOrderc('<%=departs.getId() %>');">编辑序号</a>
                        </td>
                      </tr>
                    <%} %>
             
                 </table>
                		<div class="page" >
								共<%=paginationSupport.getTotalCount()%>条,共<%=paginationSupport.getPageCount()%>页&nbsp;&nbsp;
								当前为第<%=pageNo + 1%>页&nbsp;&nbsp;

								<% if (paginationSupport.getStartIndex() > 1) { %>
                                    <a href="<%=basePath%>tjsinfo/tjsoa/system/departmentManage.do?method=departmentList&pageNo=<%=pageNo - 1%>&level=<%=level %>&id=<%=id %>">上一页</a>
								
								<% } %>
								<% if (paginationSupport.getStartIndex()
											+ paginationSupport.getPageSize() < paginationSupport
											.getTotalCount()) {
								%>
									<a href="<%=basePath%>tjsinfo/tjsoa/system/departmentManage.do?method=departmentList&pageNo=<%=pageNo + 1%>&level=<%=level %>&id=<%=id %>">下一页</a>
								
								<% } %>
								&nbsp;&nbsp; 跳转到
								<select name="selectPage" id="selectPage"
									onchange="submitpages(this.value)">
									<option value="0">
										--跳转--
									</option>
									<%
										for (int pi = 0; pi < paginationSupport.getPageCount(); pi++) {
									%>
									<option value="<%=pi%>"><%=pi + 1%></option>
									<%
										}
									%>
								</select>
								页
							</div>
              </div>
            </td>
          </tr>
      </table>
</div>
</div>
<div id=window>
			<div id=windowTop>
				<div id=windowTopContent>
					<span id="addContent">添加部门</span><span id="updateContent" style="display: none">修改序号</span>
				</div>
				<img id=windowMax src="<%=basePath%>js/common/move/images/window_max.jpg" />
				<img id=windowClose
					src="<%=basePath%>js/common/move/images/window_close.jpg" />
			</div>
			<div id=windowBottom>
				<div id=windowBottomContent></div>
			</div>
			<div id="windowContent" style="background: #D9E8F1">
				<div id="addDepartment" style="padding-top: 20px; padding-left: 20px;">
					<form action="<%=basePath%>tjsinfo/tjsoa/system/departmentManage.do?method=departmentSave&level=<%=level %>&id=<%=id %>" id="formQuery" name="formQuery" method="post">
						<table width="90%" border="0" cellspacing="0"
							cellpadding="0" class="researchtab">
							<tr>
								<td width="30%" align="right">
									部门名称：
								</td>
								<td align="left" width="70%">&nbsp;&nbsp;&nbsp;&nbsp;
									<input name="departName" id="departName" type="text" size="48" class="textinput" maxlength="24" />
								</td>
							</tr>
							<tr>
								<td width="30%" align="right">
								</td>
								<td align="left" width="70%">&nbsp;&nbsp;&nbsp;&nbsp;
								</td>
							</tr>
							<tr>
								<td width="30%" align="right">
									排列序号：
								</td>
								<td align="left" width="70%">&nbsp;&nbsp;&nbsp;&nbsp;
									<input name="orderNo" id="orderNo" type="text" size="48" class="textinput" maxlength="3"/>
								</td>
							</tr>
							<tr>
								<td width="30%" align="right">
								</td>
								<td align="left" width="70%">&nbsp;&nbsp;&nbsp;&nbsp;
								</td>
							</tr>
							<tr>
								<td height="10px;" colspan="6" align="center">
									<a id="sub" style="cursor: hand"><img src="<%=basePath%>images/qd.gif" /></a>&nbsp;&nbsp;&nbsp;&nbsp;
									<a id="resetSend" style="cursor: hand"><img src="<%=basePath%>images/qx.gif" /></a>
								</td>
							</tr>
						</table>
					</form>
				</div>
				<div id="updateOrder" style="padding-top: 20px; padding-left: 20px;display: none">
					<form action="<%=basePath%>tjsinfo/tjsoa/system/departmentManage.do?method=departmentUpdateOrder&level=<%=level %>&id=<%=id %>" id="formUpdateOrder" name="formUpdateOrder" method="post">
						<table width="90%" border="0" cellspacing="0"
							cellpadding="0" class="researchtab">
							<tr>
								<td width="30%" align="right">
									排列序号：<input id="myid" name="myid" type="hidden"/>
								</td>
								<td align="left" width="70%">&nbsp;&nbsp;&nbsp;&nbsp;
									<input name="updateOrderNo" id="updateOrderNo" type="text" size="48" class="textinput" maxlength="3"/>
								</td>
							</tr>
							<tr>
								<td width="30%" align="right">
								</td>
								<td align="left" width="70%">&nbsp;&nbsp;&nbsp;&nbsp;
								</td>
							</tr>
							<tr>
								<td height="10px;" colspan="6" align="center">
									<a id="subOrder" style="cursor: hand"><img src="<%=basePath%>images/qd.gif" /></a>&nbsp;&nbsp;&nbsp;&nbsp;
									<a id="resetSendorder" style="cursor: hand"><img src="<%=basePath%>images/qx.gif" /></a>
								</td>
							</tr>
						</table>
					</form>
				</div>
			</div>
		<img id=windowResize
			src="<%=basePath%>js/common/move/images/window_resize.gif" />
</div>
		<script type=text/javascript>
	$(document).ready(function()
	{
	
		$('#windowOpen').bind(
			'click',
			function() {
				
				
				if($('#window').css('display') == 'none') {
					$(this).TransferTo(
						{
							to:'window',
							className:'transferer2', 
							duration: 400,
							complete: function()
							{
								$('#window').show();
							}
						}
					);
					$('#selectPage').hide();
					$('#updateOrder').hide();
					$('#addDepartment').show();
					$('#updateContent').hide();
					$('#addContent').show();
				}
				this.blur();
				return false;
			}
		);
		$('#updateOrderNoWindow').bind(
			'click',
			function() {
				if($('#window').css('display') == 'none') {
					$(this).TransferTo(
						{
							to:'window',
							className:'transferer2', 
							duration: 400,
							complete: function()
							{
								$('#window').show();
							}
						}
					);
					$('#selectPage').hide();
					$('#addDepartment').hide();
					$('#updateOrder').show();
					$('#addContent').hide();
					$('#updateContent').show();
				}
				this.blur();
				return false;
			}
		);
		$('#windowClose').bind(
			'click',
			function()
			{
				$('#window').TransferTo(
					{
						to:'windowOpen',
						className:'transferer2', 
						duration: 400
					}
				).hide();
				$('#selectPage').show();
			}
		);
		$('#resetSend').bind(
			'click',
			function()
			{
				$('#window').TransferTo(
					{
						to:'windowOpen',
						className:'transferer2', 
						duration: 400
					}
				).hide();
				$('#selectPage').show();
				$('#departName').attr('value','');
				$('#orderNo').attr('value','');
				$('#updateOrderNo').attr('value','');
			}
		);
		$('#resetSendorder').bind(
			'click',
			function()
			{
				$('#window').TransferTo(
					{
						to:'updateOrderNoWindow',
						className:'transferer2', 
						duration: 400
					}
				).hide();
				$('#selectPage').show();
				$('#departName').attr('value','');
				$('#orderNo').attr('value','');
				$('#updateOrderNo').attr('value','');
			}
		);
		$('#windowMin').bind(
			'click',
			function()
			{
				$('#windowContent').SlideToggleUp(300);
				$('#windowBottom, #windowBottomContent').animate({height: 10}, 300);
				$('#window').animate({height:40},300).get(0).isMinimized = true;
				$(this).hide();
				$('#windowResize').hide();
				$('#windowMax').show();
			}
		);
		$('#windowMax').bind(
			'click',
			function()
			{
				var windowSize = $.iUtil.getSize(document.getElementById('windowContent'));
				$('#windowContent').SlideToggleUp(300);
				$('#windowBottom, #windowBottomContent').animate({height: windowSize.hb + 13}, 300);
				$('#window').animate({height:windowSize.hb+43}, 300).get(0).isMinimized = false;
				$(this).hide();
				$('#windowMin, #windowResize').show();
			}
		);
		$('#window').Resizable(
			{
				minWidth: 200,
				minHeight: 60,
				maxWidth: 700,
				maxHeight: 400,
				dragHandle: '#windowTop',
				handlers: {
					se: '#windowResize'
				},
				onResize : function(size, position) {
					$('#windowBottom, #windowBottomContent').css('height', size.height-33 + 'px');
					var windowContentEl = $('#windowContent').css('width', size.width - 25 + 'px');
					if (!document.getElementById('window').isMinimized) {
						windowContentEl.css('height', size.height - 48 + 'px');
					}
				}
			}
		);
		$('#sub').bind(
			'click',
			function()
			{
				var pattern = /^[0-9]\d*$/;
				if(!pattern.test(document.getElementById("orderNo").value)){alert("序号应为数字！"); return false;}
			    if(isEmpty(document.getElementById("departName").value) ){ alert('请输入部门名称!'); return false;}
			    if(!isChinese(document.getElementById("departName").value)){ alert('部门名称只能为中文或英文!'); return false;}
				document.formQuery.submit();
			}
		);
		$('#subOrder').bind(
			'click',
			function()
			{
				var pattern = /^[0-9]\d*$/;
				if(!pattern.test(document.getElementById("updateOrderNo").value)){alert("序号应为数字！"); return false;}
				document.formUpdateOrder.submit();
			}
		);
		
		<% 
		if(request.getAttribute("alert")!=null)out.print("alert('"+String.valueOf(request.getAttribute("alert"))+"')");
		%>
	}
);
</script>
</body>
</html>
